var CommandTable = function(pid)
{
	this.rootid = pid;
	this.rootnode = document.getElementById(this.rootid);
	this.instancename = this.rootnode.getAttribute("instancename");

	this.commandboxid = this.instancename + (new Date()).getTime().toString() + "commandbox";
	this.curtainid = this.instancename + (new Date()).getTime().toString() + "curtain";
	this.divid = this.instancename + (new Date()).getTime().toString() + "div";

	this.closecurtain = function()
	{
		var names = new Array();
		names.length = 0;
		names[names.length] = this.curtainid;
		names[names.length] = this.divid;
		for(var icnt = 0; icnt < names.length; icnt++)
		{
			try
			{
				var mya = document.getElementById(names[icnt]);
				mya.parentNode.removeChild(mya);
			}catch(err){}
		}
	}

	this.displaycurtain = function()
	{
		var canv = document.body.appendChild(document.createElement("canvas"));
		canv.style.position = "absolute";
		canv.style.top = 0;
		canv.style.left = 0;
		canv.style.zIndex = 100;
		canv.width = window.innerWidth;
		canv.height = window.innerHeight;
		canv.setAttribute("id", this.curtainid);
		canv.setAttribute("onclick", this.instancename + ".closecurtain();");
		var cx = canv.getContext("2d");
		cx.beginPath();
		cx.fillStyle = "rgba(0,0,0,0.7)";
		cx.fillRect(0,0,canv.width, canv.height);
		cx.closePath();
	}

	this.displaydiv = function()
	{
		var mydiv = document.body.appendChild(document.createElement("div"));
		mydiv.style.position = "absolute";
		mydiv.style.top = "100px";
		mydiv.style.left = "100px";
		mydiv.style.zIndex = 101;
		mydiv.setAttribute("id", this.divid);
	}

	this.display = function()
	{
		this.displaycurtain();
		this.displaydiv();
		var t = document.getElementById(this.divid).appendChild(document.createElement("table"));
		var r = t.appendChild(document.createElement("tr"));
		var d = r.appendChild(document.createElement("td"));
		var myi = d.appendChild(document.createElement("input"));
		myi.setAttribute("id", this.commandboxid);
		myi.setAttribute("maxlength", "255");
		myi.setAttribute("size", "100");
		myi = d.appendChild(document.createElement("input"));
		myi.setAttribute("type", "button");
		myi.setAttribute("value", "ok");
		myi.style.border = "none";
		myi.style.color = "white";
		myi.style.background = "transparent";
		myi.setAttribute("onclick", this.instancename + ".fire();");

		document.getElementById(this.commandboxid).focus();
	}

	this.fire = function()
	{
		var su = new ShellUtil();
		var cmdline = document.getElementById(this.commandboxid).value;
		if(cmdline != "")
		{
			try
			{
				su.run(cmdline);
			}
			catch(err)
			{
				su.run("explorer " + cmdline);
			}
			this.closecurtain();
		}
	}
}
